// 工厂模式

// 初始化一个工厂管理者
function SquareFactory() { }


// 将对应的构造函数统一

SquareFactory.prototype.Wall = function (x, y) {
    return new Wall(x, y, 'Wall', "black");
}
SquareFactory.prototype.Food = function (x, y) {
    return new Food(x, y, 'Food', "#2827ff");
}
SquareFactory.prototype.SnakeBody = function (x, y) {
    return new SnakeBody(x, y, 'SnakeBody', "#ff0");
}
SquareFactory.prototype.SnakeHead = function (x, y) {
    return new SnakeHead(x, y, 'SnakeHead', "#0ff");
}
SquareFactory.prototype.Floor = function (x, y) {
    return new Floor(x, y, 'Floor', "#14CA9E");
}

// 工厂提供创造对象的接口

SquareFactory.create = function (type, x, y) {
    if(SquareFactory.prototype[type] == undefined) {
        throw new TypeError("No This Type");
    }
    if (SquareFactory.prototype[type].prototype.__proto__ !== SquareFactory.prototype) {
        SquareFactory.prototype[type].prototype = new SquareFactory();
    }
    return new SquareFactory.prototype[type](x, y); // color 就内置

}


var wall = SquareFactory.create("Wall", 1, 1);

wall.initDomStyle();
wall.appendDom();
